package com.lianxian.xindong.life.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lianxian.xindong.life.R;
import com.lianxian.xindong.life.entities.FoodRandkingFilterOneRecyclerModel;
import com.lianxian.xindong.life.myinterface.MyCallBack;

import java.util.List;

public class FilterOnePopupWindowAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private List<FoodRandkingFilterOneRecyclerModel> list;
    private int currentPositon;
    public MyCallBack myCallBack;
    public FilterOnePopupWindowAdapter( List<FoodRandkingFilterOneRecyclerModel> list,int currentPositon,Context context,MyCallBack myCallBack) {
        this.layoutInflater = LayoutInflater.from(context);
        this.list = list;
        this.currentPositon =currentPositon;
        this.myCallBack = myCallBack;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FoodRandkingFilterOneRecyclerModel model = list.get(position);
        ViewHolder viewHolder;
        if (convertView==null){
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_food_ranking_filter_one_popupwindow,parent,false);
            viewHolder.nameLayout = convertView.findViewById(R.id.name_layout_popupwindow);
            viewHolder.nameTV = convertView.findViewById(R.id.filter_one_name_popupwindow);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.nameLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myCallBack.callback(position);
            }
        });
        if (currentPositon==position){
            viewHolder.nameLayout.setBackgroundResource(R.drawable.filter_one_backgroud);
        }else {
            viewHolder.nameLayout.setBackgroundResource(R.color.transparent);
        }
        viewHolder.nameTV.setText(model.getName());
        return convertView;
    }
    private class ViewHolder{
        private LinearLayout nameLayout;
        private TextView nameTV;

        public ViewHolder() {

        }

    }
}
